export default {
    data() {
        return {
            all_data: [],
            list: [], //数据存放
            loading: false,
            finished: false,
            refreshing: false,
            page: 1,
            size: 20,
        }
    },
    mounted() {
        clearImmediate
    },
    methods: {
        refreshingSate() {

            if (this.refreshing) {
                this.list = [];
                this.refreshing = false;
            }
        },
        onLoad_child(data, code, msg, listback = () => {}) {
            this.refreshingSate();
            if (code) {

                data.forEach(element => {
                    this.list.push(element);
                });

                this.loading = false;
                let length = data.length;
                if (length < this.size) {
                    this.finished = true;
                } else {
                    this.page += 1;
                }
                this.all_data = data
                listback()
            } else {
                this.$toast(msg)
            }
        },
        async onLoad(fun, params, listback) {
            let obj = {
                page: this.page,
                size: this.size
            }
            obj = Object.assign(obj, params);
            let { Data, Msg, IsOk } = await fun(obj);
            this.onLoad_child(Data, IsOk, Msg, listback)

        },
        onRefresh(fun, params, listback) {
            console.log("sss")
            this.page = 1;
            // 清空列表数据
            this.finished = false;
            this.refreshing = true
                // 重新加载数据
                // 将 loading 设置为 true，表示处于加载状态
            this.loading = true;
            this.onLoad(fun, params, listback);
        }
    }
}